#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e7 + 5;
const int M = 1e5 + 5;
const ll INF = 1e18;

int n, m;
int cnt[M];
queue<ll> q1, q2;
ll get() {
  ll x = q1.size() ? q1.front() : INF;
  ll y = q2.size() ? q2.front() : INF;
  ll z = min(x, y);
  if (x == z)
    q1.pop();
  else
    q2.pop();
  return z;
}

inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  n = read();
  rep(i, 1, n) {
    int x = read();
    cnt[x]++;
  }
  rep(i, 1, 1e5) rep(j, 1, cnt[i]) q1.push(i);
  ll ans = 0;
  rep(i, 1, n - 1) {
    ll x = get();
    ll y = get();
    ans += x + y;
    q2.push(x + y);
  }
  printf("%lld", ans);
  return 0;
}